'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, middleware, io } = app;
  const checkToken = middleware.checkToken();
  const admin = middleware.admin();
  const middlewareList = [ admin, checkToken ];

  router.get('/getUserInfo', ...middlewareList, controller.jwt.getUserInfo);
  router.post('/login', controller.jwt.doLogin);
  router.post('/register', controller.jwt.doRegister);

  router.get('/getConversationList', ...middlewareList, controller.conversation.getConversationList);
  router.post('/getConversationById', ...middlewareList, controller.conversation.getConversationById);
  router.post('/postMessage', ...middlewareList, controller.conversation.postMessage);
  router.post('/getConversationInfos', ...middlewareList, controller.conversation.getConversationInfos);
  router.post('/getAllConversationInfosWithStaff', ...middlewareList, controller.conversation.getAllConversationInfosWithStaff);
  router.post('/endTicket', ...middlewareList, controller.conversation.endTicket);

  router.post('/orderTicket', ...middlewareList, controller.ticket.orderTicket);
  router.post('/setTicketStaff', ...middlewareList, controller.ticket.setTicketStaff);
  router.post('/evaluate', ...middlewareList, controller.ticket.evaluate);

  router.get('/getAllStaff', ...middlewareList, controller.utils.getAllStaff);
  router.get('/getAllUsers', ...middlewareList, controller.utils.getAllUsers);
  router.post('/setPermission', ...middlewareList, controller.utils.setPermission);

  router.post('/upload', controller.upload.upload);

  io.of('/').route('server', io.controller.conversation.server);
  io.of('/manager').route('manager', io.controller.manager.manager);
};
